package tech.aistar.day10;

import java.util.Comparator;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2021/3/22 1:48 下午
 */
public class ComparatorFactory {
    public static final String BOOK_PRICE = "price";

    public static final String BOOK_ISBN = "isbn";

    //根据传入的参数,返回某个接口的具体的实现类
    public static Comparator<Book> sort(String type){
        Comparator<Book> c=null;
        switch (type){
            case BOOK_PRICE:
                c = (o1,o2)->(int)(o2.getPrice()-o1.getPrice());
                break;
            case BOOK_ISBN:
                c = (o1,o2)->o2.getIsbn().compareTo(o1.getIsbn());
                break;
        }
        return c;
    }
}
